package org.wmq.javafxmapcollectioncsserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wmq.javafxmapcollectioncsserver.model.Entity.Comment;
import org.wmq.javafxmapcollectioncsserver.model.Entity.Result;
import org.wmq.javafxmapcollectioncsserver.service.CommentService;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/{id}")
    public Result<Comment> getCommentById(@PathVariable Long id){
        return Result.ok(commentService.getById(id));
    }

    @PostMapping
    public Result<Void> saveComment(@RequestBody Comment comment){
        commentService.save(comment);
        return Result.ok();
    }

    @PutMapping
    public Result<Void> updateComment(@RequestBody Comment comment){
        commentService.updateById(comment);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    public Result<Void> dropCommentById(@PathVariable Long id){
        commentService.removeById(id);
        return Result.ok();
    }

}
